package com.tf_cut.backend.service.service;


import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.common.service.CommonServiceImpl;
import com.tf_cut.backend.mapper.ServiceRefSellerMapper;
import com.tf_cut.backend.service.pojo.ServiceRefSeller;
import com.tf_cut.backend.service.repository.ServiceRefSellerRepository;
import com.tf_cut.backend.service.vo.ServiceRefSellerResVo;
import com.tf_cut.backend.service.vo.ServiceRefSellerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Service
@Transactional
public class ServiceRefSellerServiceImpl extends CommonServiceImpl<ServiceRefSellerVo, ServiceRefSeller, String>
		implements ServiceRefSellerService {
    @PersistenceContext
    private EntityManager em;
    
    @Autowired
    private ServiceRefSellerRepository serviceRefSellerRepository;
    
	@Autowired
	private ServiceRefSellerMapper serviceRefSellerMapper;

	@Override
	public PageInfo<ServiceRefSellerResVo> findListServiceRefSeller(ServiceRefSellerVo avo) {
		com.github.pagehelper.PageHelper.startPage(avo.getPage(),avo.getRows());
		List<ServiceRefSellerResVo> list = serviceRefSellerMapper.findListServiceRefSeller(avo);
		com.github.pagehelper.PageInfo<ServiceRefSellerResVo> pageinfo = new com.github.pagehelper.PageInfo<>(list);

		PageInfo<ServiceRefSellerResVo> returnPageInfo = new PageInfo<>();
		returnPageInfo.setPage(pageinfo.getPageNum());//页码
		returnPageInfo.setPageSize(pageinfo.getPageSize());//页面大小
		returnPageInfo.setRows(pageinfo.getList());//分页结果
		returnPageInfo.setRecords((int)pageinfo.getTotal());//总记录数
		returnPageInfo.setTotal(pageinfo.getPages());//总页数
		return returnPageInfo;
	}

	@Override
	public Integer findServiceSellerNum(String serviceId, String sellerId) {
		return serviceRefSellerMapper.findServiceSellerNum(serviceId,sellerId);
	}
}
